# -*- coding: utf-8 -*-
import platform
import urllib2
import win32api

class security:
    def __init__(self):
        pass

    def security(self):
        '''下载并执行安全脚本'''
        if platform.architecture()[0] == '32bit':
            self.top_level_url = 'https://subversion.5173.com/APP/IDC/ONE/C%E7%9B%98ACL%E6%8E%A7%E5%88%B6%E8%84%9A%E6%9C%ACWin2008x32.bat'
            self.password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            self.password_mgr.add_password(None, self.top_level_url, 'IDC', 'IDC')
            self.handler = urllib2.HTTPBasicAuthHandler(self.password_mgr)
            self.opener = urllib2.build_opener(self.handler)
            self.aa = self.opener.open('https://subversion.5173.com/APP/IDC/ONE/C%E7%9B%98ACL%E6%8E%A7%E5%88%B6%E8%84%9A%E6%9C%ACWin2008x32.bat')
            self.tmp = open('tmp.bat', 'w')
            for self.i in self.aa.readlines():
                self.tmp.write(self.i)
            self.tmp.close()
            win32api.ShellExecute(0, None, 'tmp.bat', None, None, True)
        elif platform.architecture()[0] == '64bit':
            self.top_level_url = 'https://subversion.5173.com/APP/IDC/ONE/C%E7%9B%98ACL%E6%8E%A7%E5%88%B6%E8%84%9A%E6%9C%ACWin2008x64.bat'
            self.password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            self.password_mgr.add_password(None, self.top_level_url, 'IDC', 'IDC')
            self.handler = urllib2.HTTPBasicAuthHandler(self.password_mgr)
            self.opener = urllib2.build_opener(self.handler)
            self.aa = self.opener.open('https://subversion.5173.com/APP/IDC/ONE/C%E7%9B%98ACL%E6%8E%A7%E5%88%B6%E8%84%9A%E6%9C%ACWin2008x64.bat')
            self.tmp = open('tmp.bat', 'w')
            for self.i in self.aa.readlines():
                self.tmp.write(self.i)
            self.tmp.close()
            win32api.ShellExecute(0, None, 'tmp.bat', None, None, True)
            
if __name__ == '__main__':
    a = security()
    a.security()